using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class ColumnsPage : System.Web.UI.Page
{
    SqlDataSource sqlDataSource;
    GridView gridView =null;
    protected void Page_Load(object sender, EventArgs e)
    {
        AddColumns();
        FillData();                    
    }

    void FillData( )
    {
        
        sqlDataSource = new SqlDataSource();
        sqlDataSource.ConnectionString =
        WebConfigurationManager.ConnectionStrings[
            "RecruitVietnamDbConnectionString"
            ].ConnectionString;
        sqlDataSource.SelectCommandType =
        SqlDataSourceCommandType.Text;
        sqlDataSource.SelectCommand = "select " +
        "top 5 Email,CompanyName, "
        + "ContactName,Address,Activate from tblRCAccounts";
        gridView.DataSource = sqlDataSource;
        gridView.DataBind();
        this.form1.Controls.Add(gridView);
    }
    void AddColumns( )
    {
        gridView = new GridView();
        gridView.AutoGenerateColumns=false;
        
        BoundField boundField = new BoundField();
        boundField.DataField = "Email";
        boundField.HeaderText = "Email Address";
        gridView.Columns.Add(boundField);

        boundField = new BoundField();
        boundField.DataField = "CompanyName";
        boundField.HeaderText = "Company Name";
        gridView.Columns.Add(boundField);
        
        CheckBoxField checkBoxField = new CheckBoxField();
        checkBoxField.DataField="Activate";
        checkBoxField.HeaderText = "Activated";
        gridView.Columns.Add(checkBoxField);
    }
}
